package com.zhiwang.planet.ui.my

import android.os.Bundle
import android.view.View
import com.zhiwang.planet.R
import com.zhiwang.planet.di.component.DaggerUserComponent
import com.zhiwang.planet.di.module.AccountModule
import com.zhiwang.planet.di.module.AutoDisposeModule
import com.zhiwang.planet.mvp.p.UserPresenter
import com.zhiwang.planet.mvp.v.FeedBackView
import com.zhiwang.planet.ui.BaseActivity
import com.zhiwang.planet.util.Toaster
import com.zhiwang.planet.util.suicideAfterTransition
import kotlinx.android.synthetic.main.activity_feed_back.*
import javax.inject.Inject

class FeedBackActivity : BaseActivity(), FeedBackView {

    @Inject
    lateinit var userPresenter: UserPresenter

    override fun initInjection() {
        DaggerUserComponent.builder()
                .appComponent(getAppComponent())
                .accountModule(AccountModule(this))
                .autoDisposeModule(AutoDisposeModule(this))
                .build()
                .inject(this)
        userPresenter.feedbackView = this
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_feed_back)
        setSupportActionBar(toolbar)
        observeTextChangeWithTargetButtonEnableStatus(arrayOf(feedBack), sendButton)
    }

    fun sendFeedBack(v: View) {
        userPresenter.sendFeedBack(feedBack.text.toString())
    }

    override fun onFeedBackSend() {
        Toaster.message(R.string.feedback_message)
        suicideAfterTransition()
    }

    override fun onSupportNavigateUp(): Boolean {
        onBackPressed()
        return super.onSupportNavigateUp()
    }

}
